package control

import (
	"log"
	"sync"
	"vector/control/model"
	"vector/control/other"
	"vector/control/request"
	"vector/control/sse"
	"vector/control/websocket"
	"vector/tools"
)

type Task interface {
	NewTaskData(map[string]any) error
	Do()
	Result() map[string]any
	Reset()
}

var taskFactoryMap = map[string]func() any{
	"customerService": func() any { return new(websocket.CustomerService) },
	"tts":             func() any { return new(request.TTStudio) },
	"sseChat":         func() any { return new(sse.LingXiSseChat) },
	"dispatch":        func() any { return new(sse.LingXiDispatch) },
	"vectorSearch":    func() any { return new(request.VectorTask) },
	"vectorLocal":     func() any { return new(request.VectorAnalysisTask) },
	"vectorExternal":  func() any { return new(request.ExternalVectorTask) },
	"vectorAccuracy":  func() any { return new(request.VectorAccuracyTask) },
	"yyzd":            func() any { return new(request.YiYuZDTask) },
	"faq":             func() any { return new(request.FAQModelTask) },
	"14B":             func() any { return new(model.AgentModelTask) },
	"t5":              func() any { return new(request.T5) },
	"ragLabel":        func() any { return new(model.RagLabelTask) },
	"rag":             func() any { return new(model.RagTask) },
	"ragSim":          func() any { return new(other.RAGSimilarity) },
	"aiCanvas":        func() any { return new(websocket.AICanvas) },
	"ragStress":       func() any { return new(model.RagStress) },
}

// TaskPool 根据配置的RunMode获取对应的sync.Pool
var TaskPool = sync.Pool{
	New: func() any {
		if factory, exists := taskFactoryMap[tools.Config.RunMode]; exists {
			return factory()
		}
		log.Fatalf("未定义的运行模式: %s", tools.Config.RunMode)
		return nil
	},
}
